using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Dracham.TileManagement.CharacterManagement.Animation;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Dracham.TileManagement.CharacterManagement
{
    public class Model:ICloneable
    {
        private String modelId = "";
        private Double moveSpeed = 0;
        private List<Walk> walks = new List<Walk>();
        private Texture2D texture;

        #region properties 

        public Texture2D Texture
        {
            get { return this.texture; }
        }

        public List<Walk> Walks
        {
            get { return this.walks; }
        }

        public Double MoveSpeed
        {
            get { return this.moveSpeed; }
        }

        public String ModelId
        {
            get
            {
                return this.modelId;
            }
        }

        #endregion

        private Model()
        {

        }

        public Walk GetWalkByDirection(String walkDirection)
        {
            foreach (Walk w in walks)
            {
                if (w.Direction == walkDirection)
                    return w;
            }

            return null;
        }

        public static Model FromXmlNode(XmlNode modelNode, ContentManager content)
        {
            Model m = new Model();

            m.modelId = modelNode.Attributes["Name"].Value;
            m.texture = content.Load<Texture2D>(modelNode.Attributes["Source"].Value);
            m.moveSpeed = Double.Parse(modelNode.Attributes["MoveSpeed"].Value);

            foreach (XmlNode xn in modelNode.ChildNodes)
            {
                if (xn.Name == "Walk")
                {
                    m.walks.Add(Walk.FromXmlNode(xn));
                }
            }

            return m;
        }

        #region ICloneable Members

        public object Clone()
        {
            Model m = new Model();

            m.modelId = this.modelId;
            m.texture = this.texture;
            m.moveSpeed = this.moveSpeed;

            foreach (Walk w in walks)
            {
                m.walks.Add((Walk)w.Clone());
            }

            return m;
        }

        #endregion
    }
}
